package kamkor.ann.namerecog.network.parser

import scala.util.matching.Regex

/** On default, Parser surnames in following format "MarstonHamiltonVettel"  
 *  This will give 3 surnames: Marston, Hamilton and Vettel.<br><br>  
 *  
 *  Surname must start with upper case letter from [A-Z] class and then have only
 *  [a-z] letters. There must be no spaces in beetwen surnames.
 *  
 *  If user wants to use it's own regex expression for parsing, regex must be set
 *  explicitly trough constructor.
 * 
 * @author kamkor
 *
 */
class SurnamesParser(regex: Regex) {
	def this() = this("[A-Z][a-z]*".r)
	
	/** Default behaviour: "MarstonHamiltonVettel" -> "Marston", "Hamilton", "Vettel"
	 * Set regex in constructor for different parsing
	 * 
	 * @param surnames KowalskiHamiltonVettel
	 * @return array with surnames, ie. Array("Kowalski", "Hamilton", "Vettel")
	 */
	def parse(surnames: String): Array[String] = regex.findAllIn(surnames).toArray
	
	/** Parses surnames like parse(String) and applies function
	 * f to each surname. 
	 */
	def parse(surnames: String, f: String => String): Array[String] = parse(surnames).map(f)
}
